package today.rocky.boot.security.init;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import today.rocky.boot.security.entity.UserInfo;
import today.rocky.boot.security.repository.UserInfoRepository;

import javax.annotation.PostConstruct;

/**
 * @author Rocky
 * @version 1.0
 * @date 2020/5/13 10:23
 *初次启动服务需要
 */
@Service
public class DataInit {

	@Autowired
	private UserInfoRepository userInfoRepository;
	@Autowired
	private PasswordEncoder passwordEncoder;

	@PostConstruct
	public void dataInit(){
		UserInfo admin = new UserInfo();
		admin.setUsername("admin");
		admin.setPassword("123456");
		admin.setRole(UserInfo.Role.admin);
		userInfoRepository.save(admin);

		UserInfo user = new UserInfo();
		user.setUsername("user");
		user.setPassword("123456");
		user.setRole(UserInfo.Role.normal);
		userInfoRepository.save(user);

	}
}
